package com.shujia.wyh.day11;

import java.util.ArrayList;
import java.util.Collections;

/*
        Collections工具类的静态方法：
            public static <T> void sort(List<T> list)
            public static <T> int binarySearch(List<?> list,T key)
            public static <T> T max(Collection<?> coll)
            public static void reverse(List<?> list)
            public static void shuffle(List<?> list)

 */
public class CollectionsDemo {
    public static void main(String[] args) {
        //public static <T> void sort(List<T> list) 只能对List相关集合做排序
        ArrayList<Integer> list = new ArrayList<>();
        list.add(23);
        list.add(11);
        list.add(26);
        list.add(15);
        list.add(56);
        list.add(8);
        System.out.println(list);
        System.out.println("===================================");
        Collections.sort(list); //底层调用的是Arrays工具类中的快速排序的方法
        System.out.println(list);
        System.out.println("===================================");
        //[8, 11, 15, 23, 26, 56]
        //public static <T> int binarySearch(List<?> list,T key)
        int i = Collections.binarySearch(list, 100);
        System.out.println(i);
        System.out.println("===================================");
        //public static <T> T max(Collection<?> coll)
        Integer max = Collections.max(list);
        System.out.println(max);
        System.out.println("===================================");
        //public static void reverse(List<?> list)
        Collections.reverse(list);
        System.out.println(list);
        System.out.println("===================================");
        //public static void shuffle(List<?> list)
        Collections.shuffle(list);
        System.out.println(list); //[56, 11, 8, 26, 23, 15]   [15, 56, 8, 26, 11, 23]
    }
}
